﻿using System;
using System.Collections.Generic;
using System.Text;
using Vortex.SceneFramework;
using Vortex.SceneFramework.Gui;
using Vortex.Drawing;
using Vortex.Input;
using Vortex.Resources;

namespace Vortex.Demo.Pacman {

    ///<summary>Main Menu Pacman domain</summary>
    class MenuScene : Scene {
		[ElementRef]
		private Panel _mainPanel = null;
		[ElementRef]
		private Panel _aboutPanel = null;
		[ElementRef]
		private Panel _instructionsPanel = null;

		///<summary>This one is valid when submenu is opened</summary>
		private Panel _currentSubMenu;

		protected override void Load(IResourceCollection collection) {
		}

		#region Dynamically binded events

		private void StartGameButtonClick(Node sender, MouseEventInfo ei) {
			//go to domain...
			//Game.Screen.PushScene(PacmanGame.LevelScene, SceneSwitchEffects.Fade, 0.8f);
			PacmanGame.LevelScene.BeginGame(1);
		}

		private void InstructionsButtonClick(Node sender, MouseEventInfo ei) {
			GoToSubmenu(_instructionsPanel);
		}

		private void AboutButtonClick(Node sender, MouseEventInfo ei) {
			GoToSubmenu(_aboutPanel);
		}

		private void ExitButtonClick(Node sender, MouseEventInfo ei) {
			Game.Terminate();
		}

		private void BackToMenuClick(Node sender, MouseEventInfo ei) {
			BackToMenu();
		}

		#endregion

		/// <summary>
		/// Slides sub-menu based on Flow Panel
		/// </summary>
		/// <param name="menu">The menu panel to slide-in.</param>
		private void GoToSubmenu(Panel menu) {
			TimeLine.Repeat(0.3f, delegate(IActionStatus status) {
				MoveMenu(-status.Progress, _mainPanel, menu);
			});
			_currentSubMenu = menu;
		}

		/// <summary>
		/// Slide-out currently opened sub-menu and show main menu
		/// </summary>
		private void BackToMenu() {
			TimeLine.Repeat(0.3f, delegate(IActionStatus status) {
				MoveMenu(status.Progress - 1, _mainPanel, _currentSubMenu);
			});
		}

		private void MoveMenu(float progress, Panel leftMenu, Panel rightMenu) {
			progress = progress * Math.Abs(progress);
			leftMenu.Location = new Vector2(PacmanGame.SCREEN_SIZE.X * progress, leftMenu.Location.Y);
			rightMenu.Location = new Vector2(PacmanGame.SCREEN_SIZE.X * (1 + progress), leftMenu.Location.Y);
		}

    }
}
